<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChRobot;
use Mine\Abstracts\AbstractMapper;
use Mine\MineModel;
class ChGetRobotMapper extends AbstractMapper
{
    public function assignModel()
    {
        $this->model = ChRobot::class;
    }

    public function getRobot($params)
    {
        $filters = [
            'nickname' => 'like',
            'uid' => '=',
            'login_status' => '=',
            'server_id' => '=',
            'region' => 'like',
            'city' => '=',
        ];
        $query = $this->model::query()
            ->join('ch_server', 'ch_server.id', '=', 'ch_robot.server_id')
            ->select(['ch_robot.id','ch_robot.nickname','ch_robot.avatar','ch_robot.uid','ch_robot.mobile','ch_robot.login_out_time','ch_robot.corp_name',
                'ch_robot.login_status','ch_robot.first_login_time','ch_robot.login_time','ch_robot.server_id','ch_robot.created_at',
                'ch_robot.pro_name','ch_robot.city_name','ch_robot.server_pro_name','ch_robot.server_city_name'])
            ->orderBy('ch_robot.id','desc');
        $query = applyFilters($query,$params,$filters);
        $paginate = $query->paginate((int)$params['pageSize']??(MineModel::PAGE_SIZE));
        return $this->setPaginate($paginate);
    }
}